import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ELIcons from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'
import axios from 'axios'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'  
import Avue from '@smallwei/avue';
import '@smallwei/avue/lib/index.css';
import zhCn from 'element-plus/dist/locale/zh-cn.mjs' // 导入中文语言包
axios.defaults.withCredentials=true;
//登录
// router.beforeEach((to, from, next) => {
//     let isLogin = store.getters.isLogin
//     if (!isLogin && to.path != '/Login') {//未登录
//         return next({ path: "/Login" })
//     }
//     next();
// })

const app = createApp(App);
app.use(store).use(router).use(ElementPlus, {
  locale: zhCn, // 设置为中文
}).use(Avue);
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}
for (let iconName in ELIcons) {
    app.component(iconName, ELIcons[iconName])
}
app.mount('#app')

const debounce = (fn, delay) => {
    let timer
     return (...args) => {
       if (timer) {
         clearTimeout(timer)
       }
       timer = setTimeout(() => {
         fn(...args)
       }, delay)
     }
  }
    
  const _ResizeObserver = window.ResizeObserver;
  window.ResizeObserver = class ResizeObserver extends _ResizeObserver{
     constructor(callback) {
       callback = debounce(callback, 200);
       super(callback);
     }
  }